package cn.iocoder.yudao.module.bpm.message.rocketmq;

import cn.iocoder.yudao.framework.mq.rocketmq.api.producer.service.ProducerMQService;
import cn.iocoder.yudao.module.bpm.message.ProcessTaskMessage;
import cn.iocoder.yudao.module.bpm.message.consts.ProcessTaskStreamKey;
import cn.iocoder.yudao.module.bpm.message.dto.BpmProcessTaskAssignedMessage;
import cn.iocoder.yudao.module.bpm.message.dto.BpmProcessTaskCancelledMessage;
import cn.iocoder.yudao.module.bpm.message.dto.BpmProcessTaskCompletedMessage;
import cn.iocoder.yudao.module.bpm.message.dto.BpmProcessTaskCreatedMessage;
import cn.iocoder.yudao.module.bpm.message.rocketmq.dto.RocketMqBpmProcessTaskAssignedMessage;
import cn.iocoder.yudao.module.bpm.message.rocketmq.dto.RocketMqBpmProcessTaskCancelledMessage;
import cn.iocoder.yudao.module.bpm.message.rocketmq.dto.RocketMqBpmProcessTaskCompletedMessage;
import cn.iocoder.yudao.module.bpm.message.rocketmq.dto.RocketMqBpmProcessTaskCreatedMessage;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class RocketMqProcessTaskMessage implements ProcessTaskMessage {

    private final ProducerMQService rocketMQService;

    public RocketMqProcessTaskMessage(ProducerMQService rocketMQService) {
        this.rocketMQService = rocketMQService;
    }

    @Override
    public void onProcessInstanceTaskCreatedMsg(BpmProcessTaskCreatedMessage bpmProcessTaskCreatedMessage) {
        RocketMqBpmProcessTaskCreatedMessage msg = new RocketMqBpmProcessTaskCreatedMessage();
        msg.setBpmProcessMessage(bpmProcessTaskCreatedMessage);
        rocketMQService.sendMessage(ProcessTaskStreamKey.PROCESS_INSTANCE_TASK_CREATED_MSG_STREAM,msg);
    }

    @Override
    public void onProcessInstanceTaskAssignedMsg(BpmProcessTaskAssignedMessage bpmProcessTaskAssignedMessage) {
        RocketMqBpmProcessTaskAssignedMessage msg = new RocketMqBpmProcessTaskAssignedMessage();
        msg.setBpmProcessMessage(bpmProcessTaskAssignedMessage);
        rocketMQService.sendMessage(ProcessTaskStreamKey.PROCESS_INSTANCE_TASK_ASSIGNED_MSG_STREAM,msg);
    }

    @Override
    public void onProcessInstanceTaskCleanMsg(BpmProcessTaskCancelledMessage bpmProcessTaskCancelledMessage) {
        RocketMqBpmProcessTaskCancelledMessage msg = new RocketMqBpmProcessTaskCancelledMessage();
        msg.setBpmProcessMessage(bpmProcessTaskCancelledMessage);
        rocketMQService.sendMessage(ProcessTaskStreamKey.PROCESS_INSTANCE_TASK_CLEAN_MSG_STREAM,msg);
    }

    @Override
    public void onProcessInstanceTaskFinishedMsg(BpmProcessTaskCompletedMessage bpmProcessTaskCompletedMessage) {
        RocketMqBpmProcessTaskCompletedMessage msg = new RocketMqBpmProcessTaskCompletedMessage();
        msg.setBpmProcessMessage(bpmProcessTaskCompletedMessage);
        rocketMQService.sendMessage(ProcessTaskStreamKey.PROCESS_INSTANCE_TASK_FINISHED_MSG_STREAM,msg);
    }
}
